<%--
 *  File:    CategorySummary.jsp
 *  @Author: Langerwang 
 *  Date:    2001/01/14
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  //init param
  Category cat = Category.getInstance("jsp.CategorySummary");  
  String privilegeCode = "10201,L201";
  String strModuleName = "PCM";    
%>



<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
 


<html>
	<head>
		<title></title>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
    <SCRIPT language=JavaScript1.2 src="../../css/menu.js"></SCRIPT>
    <script language="JavaScript" src="../../css/<%= strLanguageCode %>/script.js"></script>
    <script language="JavaScript" src="../../js/FuncLib.js"></script>
    <link rel="stylesheet" href="../../css/cn/widget.css" type="text/css">
    <script language="JavaScript" src="../../js/opal2/mootools.js"></script>
    <script language="JavaScript" src="../../js/opal2/opal2.js"></script>
    
    <PageFlow:CheckPageFlow pageName="categorysummary"/>
    	<%
    	  Vector categories = (Vector)pageContext.getAttribute("categorytree");
    	  if(categories == null){
    	    categories = new Vector();
    	  } 
    	  cat.debug("The categories is :" + categories.size() + categories);
    	  OvalTree initTree = new OvalTree(categories,"categoryid","parentcategoryid","grade");
    	  initTree.setRecursiveLimit(2000);
    	  Vector categoryTree = (Vector)initTree.getTreeVector(new Integer(-1000),1);  
    	  cat.debug("The tree's size is :" + categoryTree.size());
    	  cat.debug("The tree is :" + categoryTree);
    	%>
    	
    <script language="JavaScript">
    	parent.rightFrame.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
    	
    	function page_view(id,grade,isbottom,parentid,cid){
    	  document.categorysummaryform.categoryid.value = id;
    	  document.categorysummaryform.grade.value = grade; 
    	  document.categorysummaryform.isbottom.value = isbottom;  
    	  document.categorysummaryform.parentcategoryid.value = parentid;
    	  document.categorysummaryform.cid.value = cid;
    	  
    	  if(id == null || id.length == 0 || id == "" || id < 0 || id == -1){
    	  	alert('<%=message.getMessageDesc("PLEASE_SELECT") %>');
    	  	return;
    	  }
    	  if (!grade){
    	    id = -1;
    	  };
    	  var link = "CategoryInfo.jsp?<%= OvalTools.randomURL() %>&categoryid=" + id
    	           + "&languagecode=" + "<%= strLanguageCode %>";
    	         
    	  parent.rightFrame.location.href = link;
    	  
    	}
    	
    	function page_addnewchild(){
        var selectedNode = $('treeView1').selectedNode;
        if ($defined(selectedNode)){
          var id = selectedNode.id;
    	  	var gradev;
    	  	var newchildurl = "CategoryEdit.jsp?<%= OvalTools.randomURL() %>&languagecode=" + "<%= strLanguageCode %>";
    		
    	  	if (selectedNode.grade == null || id == null || id.length == 0 || id == "" || id < 0 || id == -1){
    	  		newchildurl += "&grade=1"; 
    	  		id = -1;
    	  	}else{
    		  	gradev = new Number(1) + new Number(selectedNode.grade); 
    		  	newchildurl += "&grade=" + gradev + "&parentcategoryid=" + id;
    		  	
    		  }
    		
    		  parent.rightFrame.location.href = newchildurl;                     
        }else{
        	alert('<%= message.getMessageDesc("PLEASE_SELECT")%>');
        }
    	}
    	
    	function page_edit(){
        var selectedNode = $('treeView1').selectedNode;  
        //add banshang
        //start
        if(!selectedNode){
            alert('<%= message.getMessageDesc("PLEASE_SELECT")%>');
            return ;
        }
        //end   
    		var id = selectedNode.id;
    		if(id == 'opal-gen1'){
        		alert('<%= message.getMessageDesc("CAN_NOT_EDIT_IT")%>');
        		return;
    		}
    		if(id == null || id.length == 0 || id == "" || id < 0 || id == -1 ){
    			return;
    		}
    		var pid = selectedNode.parentcategoryid;
    		var editurl = "CategoryEdit.jsp?<%= OvalTools.randomURL() %>&categoryid=" + id
    		            + "&languagecode=" + "<%= strLanguageCode %>";
    		            
    		if(pid!=null && pid != 0 && pid != -1)
    		  editurl += "&parentcategoryid=" + pid;
    		parent.rightFrame.location.href = editurl;
    	}
    	
    	function page_delete(){
        var selectedNode = $('treeView1').selectedNode;  
        //add banshang
        //start
        if(!selectedNode){
            alert('<%= message.getMessageDesc("PLEASE_SELECT")%>');
            return ;
        }
        //end    	
    		var id = selectedNode.id;
    		var isbottom = selectedNode.isbottom; 
    		
    		if(id == null || id.length == 0 || id == "" || id == "-1"){
    			alert('<%=message.getMessageDesc("MUST_SELECT_ONE_RECORD_TO_DEL",label.getLabelName("L_ProductCategory",false)) %>');
    			return;
    		}
    		
    		if(!(isbottom == "Y" || isbottom == "y")){
    			alert('<%=message.getMessageDesc("NOT_LEAF",label.getLabelName("L_ProductCategory",false))%>');
    			return;
    		}
    		
    		var flag = confirm('<%=message.getMessageDesc("ARE_YOU_SURE_DEL")%>');
    		if(!flag) return;
    		document.categorysummaryform.parentcategoryid.value = selectedNode.mother.id;
    		document.categorysummaryform.actionname.value = "delete";
    		document.categorysummaryform.target = "_parent"; 
    		isRunning = true; 
    		document.categorysummaryform.submit();
    	}
    	
    	function page_map(){
    		var id = document.categorysummaryform.categoryid.value;
    		if(id == null || id.length == 0 || id == "" || id < 0 || id == -1){
    			alert('<%=message.getMessageDesc("PLEASE_SELECT",label.getLabelName("L_ProductCategory",false)) %>');
    			return;
    		}
    		var link = "CategoryUNSPSC.jsp?<%= OvalTools.randomURL() %>&categoryid=" + id 
    		         + "&languagecode=" + "<%= strLanguageCode %>" ;
    		var cid = document.categorysummaryform.cid.value;
    		
    		if(cid != null && cid != -1 && cid != 0 && !isEmpty(cid)){
    			link = link + "&cid=" + cid;
    		}
    		parent.rightFrame.location.href = link;
    	}
    	
    	function setRoot(){
    		document.categorysummaryform.categoryid.value = "";
    		document.categorysummaryform.grade.value = 0; 
    		document.categorysummaryform.isbottom.value = "Y";  
    		document.categorysummaryform.parentcategoryid.value = "";  
    		document.categorysummaryform.cid.value = ""; 
    		return;
    	}
    	
    	function dosth(){
    		return;
    	}
    	
    	function page_ajaxgo(){
        $('treeView1').selectedNode.clearChildren();
    	}
    	
			window.addEvent('domready', function() {	
				opal.widget.TreeView.image.path = '../../images/';	
				var treeView = new opal.widget.TreeView({
					id: 'treeView1'
				});
				
				treeView.ajaxHelper.pageName = 'categorysummary';
				treeView.ajaxHelper.actionName = 'gobyajax';	
				treeView.ajaxHelper.staticParams = '';	
				treeView.ajaxHelper.dynamicParams = '';	
				treeView.DataPackName = 'categorytree';								
				treeView.idName = 'categoryid';
				treeView.textName = 'categoryname';
				treeView.isBottomName = 'isbottom';
				treeView.onRequestData = function(Node, ajaxHelper){
				  if ($defined(Node.grade)){
                   ajaxHelper.dynamicParams = 'parentcategoryid=' + Node.id;					  
				  }else{
				    ajaxHelper.dynamicParams = 'grade=1';					  
				  }
				};				
				treeView.onNodeGetData = function(Node, data){
				  Node.grade = data.grade;
				  Node.isbottom = data.isbottom;		  
				  Node.parentcategoryid = data.parentcategoryid;
				  Node.cid = data.cid;
				};
				treeView.onSelect = function(Node){
				  page_view(Node.id, Node.grade, Node.isbottom, Node.parentid, Node.cid);
				};
											
				treeView.iniRoot('产品分类');
			});
				    	
    </script>
  </head>
  
  <body>	 
		<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
			<form name="categorysummaryform" method="post" action="../../Dispatcher">
				<input type="hidden" name="pagename" value="categorysummary">
				<input type="hidden" name="actionname">
				
				<input type="hidden" name="categoryid">
				<input type="hidden" name="isbottom">
				<input type="hidden" name="grade">
				<input type="hidden" name="parentcategoryid">
				<input type="hidden" name="cid">
				
				<input type="hidden" name="languagecode" value="<%= strLanguageCode %>">
				
			<tr>
				<td valign="top"> 
					<table width="100%" border="0" cellpadding="0" cellspacing="0">
						<tr> 
							<td class="summary_top"></td>
						</tr>
					</table>
					
					<table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" 
						     cellspacing="0" align="center" height="87%">
						<tr> 
							<td colspan="-1" class="deepblue-left"><img src="../../images/<%= strLanguageCode %>/quote.gif" 
								  width="16" height="11"> 
							<%= label.getLabelName("L_ProductCategory") + label.getLabelName("L_Colon") %>
						  </td>
					  </tr>
					  
					  <tr> 
					  	<td cellspacing="0" width="100%"> 
					  		
					  		<div id=div2 style="OVERFLOW: scroll; WIDTH: 234; HEIGHT: 465">
					  		<div id="treeView1"></div>						  		
					  	</td>
            </tr>
            
            <tr>
            	<td class="td-listrom">&nbsp;</td>
            </tr>                        
          </table>
          
          <table border="0" cellspacing="1" width="100%">
          	<tr>
          		<%
          		HashMap userInfo = (HashMap)session.getAttribute("userinfo");
          		int grade = -1;
          		if(userInfo.get("grade") != null){
          		  grade = ((Integer)userInfo.get("grade")).intValue();
          		}
          		
          		if(grade == 1){
          		%>
          		
          		<td class="td_center"><a onclick="page_edit()"><custom:button type="1" label="L_Edit" imgsrc="edit.gif" border="0" style="width:60" privilegeCode="MB-CPFL01"/></a>
          			              &nbsp;<a onclick="page_delete()"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60" privilegeCode="MB-CPFL02"/></a>
          			                <br><a onclick="page_addnewchild()"><custom:button type="1" label="L_CreatSubCategory" imgsrc="CreatSubCategory.gif" border="0" privilegeCode="MB-CPFL03"/></a>
          			              &nbsp;<!-- 
          			              <a onclick="page_map()"><custom:button type="1" label="L_MapToNSPSC" imgsrc="MapToNSPSC.gif" border="0"/></a>
          			              --> 
          	  </td>
          	  <%}%>
          	</tr> 
          </table>                                
        </td>
      </tr>
      </form>
    </table>
  </body>
  <script language="JavaScript">
  var ht = document.body.clientHeight - 100;
  if(ht < 0 )
    ht = 0;
  div2.style.height= ht;
  </script>
  <SCRIPT language=JavaScript1.2>initIt(categorysummaryform,'../../images/<%= strLanguageCode %>/');</SCRIPT>
</html>


